<?php
/**
 * bs多规格sku商城系统
 * ============================================================================
 * 版权所有 2024-2099 wltx666.com，并保留所有权利。
 * 网站地址: https://wltx666.com
 * ============================================================================
 * Author: 草上飞
 * Email: wltx@alipay168.cn
 * QQ: 2719875001
 * Date: 2024/12/27
 * 描述:
 */

namespace app\job;

use app\result\TimeQueueResult;
use think\queue\Job;

class Task
{
    public function fire(Job $job, $data)
    {
        bs_log($data, 'fire', 'queue_diy_task.log');
        $res = (new TimeQueueResult())->do_job($data['id'] ?? 0);

        bs_log($res, 'res', 'queue_diy_task.log');

        if ($res['code'] === 0) {
            if (!empty($res['data']['delay'])) {
                $job->release($res['data']['delay']);
            } else {
                $job->delete();
            }
            return true;
        }

        // 重试三次失败 todo...
        if ($job->attempts() == 3) {
            $job->delete();
            return false;
        }
        return false;
    }


}
